<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Putting it all Together - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/learning.paginator.together.html">Inglês (English)</a></li>
    <li><a href="../pt-br/learning.paginator.together.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.paginator.control.html">Pagination Control and ScrollingStyles</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.paginator.html">Getting Started with Zend_Paginator</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="reference.html">Zend Framework Reference</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="learning.paginator.together" class="section"><div class="info"><h1 class="title">Putting it all Together</h1></div>
    

    <p class="para">
        You have seen how to create a Paginator object, how to render the items on the current page,
        and how to render a navigation element to browse through your pages. In this section you
        will see how Paginator fits in with the rest of your MVC application.
    </p>

    <p class="para">
        In the following examples we will ignore the best practice implementation of using a Service
        Layer to keep the example simple and easier to understand. Once you get familiar with using
        Service Layers, it should be easy to see how Paginator can fit in with the best practice
        approach.
    </p>

    <p class="para">
        Lets start with the controller. The sample application is simple, and we&#039;ll just put
        everything in the IndexController and the IndexAction. Again, this is for demonstration
        purposes only. A real application should not use controllers in this manner.
    </p>

    <pre class="programlisting brush: php">
class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        // Setup pagination control view script. See the pagation control tutorial page
        // for more information about this view script.
        Zend_View_Helper_PaginationControl::setDefaultViewPartial(&#039;controls.phtml&#039;);

        // Fetch an already instantiated database connection from the registry
        $db = Zend_Registry::get(&#039;db&#039;);

        // Create a select object which fetches blog posts, sorted decending by date of creation
        $select = $db-&gt;select()-&gt;from(&#039;posts&#039;)-&gt;sort(&#039;date_created DESC&#039;);

        // Create a Paginator for the blog posts query
        $paginator = Zend_Paginator::factory($select);

        // Read the current page number from the request. Default to 1 if no explicit page number is provided.
        $paginator-&gt;setCurrentPageNumber($this-&gt;_getParam(&#039;page&#039;, 1));

        // Assign the Paginator object to the view
        $this-&gt;view-&gt;paginator = $paginator;
    }
}
</pre>


    <p class="para">
        The following view script is the index.phtml view script for the IndexController&#039;s
        indexAction. The view script can be kept simple. We&#039;re assuming the use of the default
        ScrollingStyle.
    </p>

    <pre class="programlisting brush: php">
&lt;ul&gt;
&lt;?php
// Render each the title of each post for the current page in a list-item
foreach ($this-&gt;paginator as $item) {
    echo &#039;&lt;li&gt;&#039; . $item-&gt;title . &#039;&lt;/li&gt;&#039;;
}
?&gt;
&lt;/ul&gt;
&lt;?php echo $this-&gt;paginator; ?&gt;
</pre>


    <p class="para">
        Now navigate to your project&#039;s index and see Paginator in action. What we have discussed
        in this tutorial is just the tip of the iceberg. The reference manual and
        <acronym class="acronym">API</acronym> documentation can tell you more about what you can do with
        <span class="classname">Zend_Paginator</span>.
    </p>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.paginator.control.html">Pagination Control and ScrollingStyles</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.paginator.html">Getting Started with Zend_Paginator</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="reference.html">Zend Framework Reference</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="learning.html">Learning Zend Framework</a></li>
  <li class="header up"><a href="learning.paginator.html">Getting Started with Zend_Paginator</a></li>
  <li><a href="learning.paginator.intro.html">Introduction</a></li>
  <li><a href="learning.paginator.simple.html">Simple Examples</a></li>
  <li><a href="learning.paginator.control.html">Pagination Control and ScrollingStyles</a></li>
  <li class="active"><a href="learning.paginator.together.html">Putting it all Together</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>